// -*- C++ -*-
-// $Id: babeldata.h,v 1.6 2010/04/11 18:11:46 robertl Exp $
+// $Id: babeldata.h,v 1.7 2010/04/12 02:53:04 robertl Exp $
//------------------------------------------------------------------------
//
// Copyright (C) 2009 S. Khai Mong <khai@mangrai.com>.
upgradeCheckMethod(0),
upgradeCheckTime(QDateTime(QDate(2001, 1, 1), QTime(0, 0))),
installationUuid(QUuid::createUuid().toString()),
+ upgradeCallbacks(0),
+ upgradeDeclines(0),
+ upgradeErrors(0),
+ upgradeOffers(0),
startupVersionCheck(true),
reportStatistics(true),
allowBetaUpgrades(false)
sg.addVarSetting(new IntSetting("app.upgradeCheckMethod", upgradeCheckMethod));
sg.addVarSetting(new DateTimeSetting("app.upgradeCheckTime", upgradeCheckTime));
sg.addVarSetting(new StringSetting("app.installationUuid", installationUuid));
+ sg.addVarSetting(new IntSetting("app.upgradeCallbacks", upgradeCallbacks));
+ sg.addVarSetting(new IntSetting("app.upgradeDeclines", upgradeDeclines));
+ sg.addVarSetting(new IntSetting("app.upgradeErrors", upgradeErrors));
+ sg.addVarSetting(new IntSetting("app.upgradeOffers", upgradeOffers));
// Global preferences.
sg.addVarSetting(new BoolSetting("app.startupVersionCheck", startupVersionCheck));
int upgradeCheckMethod;
QDateTime upgradeCheckTime;
QString installationUuid;
+ int upgradeCallbacks;
+ int upgradeDeclines;
+ int upgradeErrors;
+ int upgradeOffers;
// Global preferences.
bool startupVersionCheck;
// -*- C++ -*-
-// $Id: mainwindow.cpp,v 1.19 2010/04/11 22:38:06 robertl Exp $
+// $Id: mainwindow.cpp,v 1.20 2010/04/12 02:53:03 robertl Exp $
//------------------------------------------------------------------------
//
// Copyright (C) 2009 S. Khai Mong <khai@mangrai.com>.
//--- Restore from registry
restoreSettings();
- upgrade = new UpgradeCheck(parent, formatList);
+ upgrade = new UpgradeCheck(parent, formatList, bd);
if (bd.startupVersionCheck) {
- upgrade->checkForUpgrade(babelVersion, bd.upgradeCheckMethod,
- bd.upgradeCheckTime, bd.installationUuid,
- bd.reportStatistics, allowBetaUpgrades());
+ upgrade->checkForUpgrade(babelVersion, bd.upgradeCheckTime,
+ allowBetaUpgrades());
}
}
//------------------------------------------------------------------------
void MainWindow::upgradeCheckActionX()
{
- upgrade->checkForUpgrade(babelVersion, bd.upgradeCheckMethod,
- QDateTime(QDate(2000, 1, 1), QTime(0, 0)),
- bd.installationUuid,
- bd.reportStatistics, allowBetaUpgrades());
+ upgrade->checkForUpgrade(babelVersion,
+ QDateTime(QDate(2000, 1, 1), QTime(0, 0)),
+ allowBetaUpgrades());
}
//------------------------------------------------------------------------
// -*- C++ -*-
-// $Id: upgrade.cpp,v 1.24 2010/04/11 18:11:47 robertl Exp $
+// $Id: upgrade.cpp,v 1.25 2010/04/12 02:53:04 robertl Exp $
/*
Copyright (C) 2009, 2010 Robert Lipe, robertlipe@gpsbabel.org
*/
-#include "upgrade.h"
+#include "babeldata.h"
#include "format.h"
+#include "upgrade.h"
#include "../config.h"
#include "../gbversion.h"
static const bool testing = false;
#endif
-UpgradeCheck::UpgradeCheck(QWidget *parent, QList<Format> &formatList) :
+UpgradeCheck::UpgradeCheck(QWidget *parent, QList<Format> &formatList,
+ BabelData& bd) :
QObject(parent),
- http(0), formatList_(formatList), updateStatus_(updateUnknown)
+ http(0),
+ formatList_(formatList),
+ updateStatus_(updateUnknown),
+ bd_(bd)
{
}
}
-UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString ¤tVersionIn,
- int checkMethod,
+UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(
+ const QString ¤tVersionIn,
const QDateTime &lastCheckTime,
- const QString &installationUuid,
- bool reportStatistics,
bool allowBeta)
{
currentVersion = currentVersionIn;
currentVersion.remove("GPSBabel Version ");
- upgradeCheckMethod = checkMethod;
QDateTime soonestCheckTime = lastCheckTime.addDays(1);
if (!testing && QDateTime::currentDateTime() < soonestCheckTime) {
QString args = "current_version=" + currentVersion;
args += "¤t_gui_version=" VERSION;
- args += "&installation=" + installationUuid;
+ args += "&installation=" + bd_.installationUuid;
args += "&os=" + getOsName();
#if HAVE_UNAME
struct utsname utsname;
args += QString("&beta_ok=%1").arg(allowBeta);
args += "&lang=" + QLocale::languageToString(locale.language());
args += "&last_checkin=" + lastCheckTime.toString(Qt::ISODate);
+ args += QString("&ugcb=%1").arg(bd_.upgradeCallbacks);
+ args += QString("&ugdec=%1").arg(bd_.upgradeDeclines);
+ args += QString("&ugoff=%1").arg(bd_.upgradeOffers);
+ args += QString("&ugerr=%1").arg(bd_.upgradeErrors);
int j = 0;
if (wc)
args += QString("&uc%1=wr/%2/%3").arg(j++).arg(formatName).arg(wc);
}
- if (j && reportStatistics)
+ if (j && bd_.reportStatistics)
args += QString("&uc=%1").arg(j);
if (false && testing)
void UpgradeCheck::httpRequestFinished(int requestId, bool error)
{
- if (http == 0 || error)
+ bd_.upgradeCallbacks++;
+
+ if (http == 0 || error) {
+ bd_.upgradeErrors++;
return;
+ }
- if (requestId != httpRequestId)
+ // This is not an error state; it's just the internal state of Qt's network
+ // stack flailing around.
+ if (requestId != httpRequestId) {
return;
+ }
QString oresponse(http->readAll());
QDomDocument document;
- if (!document.setContent(oresponse))
+ int line = -1;
+ QString error_text;
+ // This shouldn't ever be seen by a user.
+ if (!document.setContent(oresponse, &error_text, &line)) {
+ QMessageBox::critical(0, tr("Error"),
+ tr("Invalid return data at line %1: %2.")
+ .arg(line)
+ .arg( error_text));
+ bd_.upgradeErrors++;
return;
+ }
QString response;
QString upgradeText;
upgradeText = upgrade.firstChildElement("overview").text();
// String compare, not a numeric one. Server will return "best first".
if((updateVersion > currentVersion) && updateCandidate) {
+ bd_.upgradeOffers++;
updateStatus_ = updateNeeded;
response = tr("A new version of GPSBabel is available.<br />"
"Your version is %1 <br />"
// downloadUrl.addQueryItem("os", getOsName());
QDesktopServices::openUrl(downloadUrl);
default: ;
+ bd_.upgradeDeclines++;
}
}
*/
+#include "babeldata.h"
#include "format.h"
#include <QDialog>
#include <QDateTime>
class UpgradeCheck : public QObject {
Q_OBJECT
public:
- //UpgradeCheck(QWidget *parent = 0);
- UpgradeCheck(QWidget *parent, QList<Format> &formatList);
+ UpgradeCheck(QWidget *parent, QList<Format> &formatList, BabelData& bd);
~UpgradeCheck();
typedef enum {
updateCurrent,
updateNeeded,
} updateStatus;
-
UpgradeCheck::updateStatus checkForUpgrade(const QString &babelVersion,
- int upgradeCheckMethod,
const QDateTime &lastCheckTime,
- const QString &installationUuid,
- bool reportStatistics,
- bool allowBeta
- );
+ bool allowBeta);
QDateTime getUpgradeWarningTime() {
return upgradeWarningTime;
}
QString getOsVersion(void);
QList<Format> &formatList_;
updateStatus updateStatus_;
+ BabelData& bd_;
private slots:
void httpRequestFinished(int requestId, bool error);